< previous page page_374 next page >

Page 374
aspect ratio of the selected region is negative. The subroutine first computes the region's new width and height based on the absolute value of the region's aspect ratio. It then uses the sign of the original aspect ratio to make the width or height of the selected area negative if necessary.
Example program Aspect demonstrates this type of constrained region selection. Enter an aspect ratio in the text box. Then use the mouse to select a region. Notice what happens if you drag the mouse to the left or above the point you originally select.
If you select an aspect ratio that is very large or very close to zero, the region you select will grow very quickly as you move the mouse. In fact, it may grow so quickly that the rubber band box coordinates become too large to fit within an integer variable, and the program will crash. The following code shows the key parts of sample program Aspect.
e10a6a0a59f035e870d90cca05b85fce.gif
Option Explicit

Private SelectInProgress As Boolean
Private StartX As Single
Private StartY As Single
Private LastX As Single
Private LastY As Single
Private OldMode As Integer
Private ViewAspect As Single

' Begin selecting the region.
Private Sub Form_MouseDown(Button As Integer, _
    Shift As Integer, X As Single, Y As Single)

    SelectInProgress = True

    ' For demonstration purposes, get the desired

    ' aspect ratio from a TextBox.

    ViewAspect = CSng(txtAspect.Text)

    ' Save the current drawing mode.
    OldMode = DrawMode

    ' Use invert mode for the rubberband box.
    DrawMode = vbInvert

    StartX = X
    StartY = Y
    LastX = X
    LastY = Y
    Line (StartX, StartY)-(LastX, LastY), , B
End Sub

' Update the region selected.
Private Sub Form_MouseMove(Button As Integer, _

 
< previous page page_374 next page >